package ac.svn.accesscontrol.store;

public class AccessUnit implements ISVNItem
{
	private String ownerId;
	private boolean readEnabled;
	private boolean writeEnabled;
	private String locationPath;
	
	public String getOwnerId() {
		return ownerId;
	}
	public void setOwnerId(String ownerId) {
		this.ownerId = ownerId;
	}
	public boolean isReadEnabled() {
		return readEnabled;
	}
	public void setReadEnabled(boolean readEnabled) {
		this.readEnabled = readEnabled;
	}
	public boolean isWriteEnabled() {
		return writeEnabled;
	}
	public void setWriteEnabled(boolean writeEnabled) {
		this.writeEnabled = writeEnabled;
	}
	public AccessUnit(String ownerId, boolean readEnabled, boolean writeEnabled) {
		super();
		this.ownerId = ownerId;
		this.readEnabled = readEnabled;
		this.writeEnabled = writeEnabled;
	}
	public AccessUnit(String ownerId) {
		super();
		this.ownerId = ownerId;
		this.readEnabled = true;
		this.writeEnabled = false;
	}
	
	public void setPermission(String prmStr)
	{
		System.out.println("AccessString:" + prmStr);
		if(!prmStr.toLowerCase().contains("r"))
		{
			this.readEnabled = false;
		}
		
		if(prmStr.toLowerCase().contains("w"))
		{
			this.writeEnabled = true;
		}
		
		if(null == prmStr || prmStr.isEmpty() || (0 == prmStr.length()))
		{
			this.readEnabled = false;
			this.writeEnabled = false;
		}
		
		System.out.println("Read:" + readEnabled + "\tWrite:" + writeEnabled);
	}
	public String getLocationPath() {
		return locationPath;
	}
	public void setLocationPath(String locationPath) {
		this.locationPath = locationPath;
	}
	@Override
	public String toString() {
		return "AccessUnit\nOwnerId=" + ownerId + "\nReadEnabled="
				+ readEnabled + "\nWriteEnabled=" + writeEnabled
				+ "\nLocationPath=" + locationPath + "]";
	}
	@Override
	public String getName() {
		return getOwnerId();
	}
	@Override
	public String getTooltipText() {
		return "<HTML>AccessUnit<br>OwnerId=" + ownerId + "<br>ReadEnabled="
			+ readEnabled + "<br>WriteEnabled=" + writeEnabled
			+ "<br>LocationPath=" + locationPath + "]";
	}
	
	
	

}
